package com.group.mall.mapper;

import com.group.mall.domain.POJO.Order;
import com.group.mall.domain.POJO.OrderDetail;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrdersMapper {

    @Select("SELECT * FROM hmall.`order` WHERE user_id = #{userId}")
    List<Order> selectAllOrdersByUserId(Long userId);

    @Select("SELECT * FROM hmall.`order_detail` WHERE order_id = #{orderId}")
    OrderDetail selectOrderDetailByOrderId(Integer orderId);

    @Select("select * from hmall.`order` where user_id = #{userId} and status = #{status}")
    List<Order> selectOrderByStatus(@Param("userId") Long userId, @Param("status") Integer status);

    //根据订单id查询订单
    @Select("select * from hmall.`order` where order_id = #{orderId}")
    Order selectOrderByOrderId(Long orderId);

    List<OrderDetail> selectOrderDetailByKeyword(String keyword);

    Boolean updateOrderStatus(Order order);

    //更新订单详情的操作
    @Update("UPDATE hmall.`order_detail` SET operation = #{operation} WHERE order_id = #{orderId}")
    Boolean updateOrderDetailOperation(@Param("orderId") Long orderId, @Param("operation") String operation);

    void insertOrder(Order order);

    void insertOrderDetail(OrderDetail orderDetail);

    //删除订单
    @Delete("delete from hmall.`order` where order_id = #{orderId}")
    Boolean delateOrder(Long orderId);

    //删除订单详情
    @Delete("delete from hmall.`order_detail` where order_id = #{orderId}")
    boolean delateOrderDetail(Long orderId);
}
